/*     */ package com.zimbra.cs.account.callback;
/*     */ 
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AttributeCallback;
/*     */ import com.zimbra.cs.account.AttributeCallback.SingleValueMod;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AccountStatus
/*     */   extends AttributeCallback
/*     */ {
/*     */   public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry)
/*     */     throws ServiceException
/*     */   {
/*  47 */     AttributeCallback.SingleValueMod mod = singleValueMod(attrName, value);
/*  48 */     if (mod.unsetting()) {
/*  49 */       throw ServiceException.INVALID_REQUEST("zimbraAccountStatus is a required attribute", null);
/*     */     }
/*  51 */     String status = mod.value();
/*     */     
/*  53 */     if ((status.equals("closed")) || (status.equals("pending"))) {
/*  54 */       attrsToModify.put("zimbraMailStatus", "disabled");
/*  55 */     } else if (attrsToModify.get("zimbraMailStatus") == null)
/*     */     {
/*  57 */       attrsToModify.put("zimbraMailStatus", "enabled");
/*     */     }
/*     */     
/*  60 */     if (((entry instanceof Account)) && (status.equals("active"))) {
/*  61 */       if (entry.getAttr("zimbraPasswordLockoutFailureTime", null) != null)
/*  62 */         attrsToModify.put("zimbraPasswordLockoutFailureTime", "");
/*  63 */       if (entry.getAttr("zimbraPasswordLockoutLockedTime", null) != null) {
/*  64 */         attrsToModify.put("zimbraPasswordLockoutLockedTime", "");
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void postModify(CallbackContext context, String attrName, Entry entry)
/*     */   {
/*  71 */     if (context.isDoneAndSetIfNot(AccountStatus.class)) {
/*  72 */       return;
/*     */     }
/*     */     
/*  75 */     if ((!context.isCreate()) && 
/*  76 */       ((entry instanceof Account))) {
/*     */       try {
/*  78 */         handleAccountStatusClosed((Account)entry);
/*     */       }
/*     */       catch (ServiceException se) {
/*  81 */         ZimbraLog.account.warn("unable to remove account address and aliases from all DLs for closed account", se);
/*  82 */         return;
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private void handleAccountStatusClosed(Account account) throws ServiceException
/*     */   {
/*  89 */     Provisioning prov = Provisioning.getInstance();
/*  90 */     String status = account.getAccountStatus(prov);
/*     */     String[] addrToRemove;
/*  92 */     if (status.equals("closed")) {
/*  93 */       ZimbraLog.misc.info("removing account address and all its aliases from all distribution lists");
/*     */       
/*  95 */       addrToRemove = new String[] { account.getName() };
/*     */       
/*  97 */       Set<String> dlIds = prov.getDistributionLists(account);
/*  98 */       for (String dlId : dlIds) {
/*  99 */         DistributionList dl = prov.get(Key.DistributionListBy.id, dlId);
/* 100 */         if (dl != null) {
/*     */           try
/*     */           {
/* 103 */             prov.removeMembers(dl, addrToRemove);
/*     */           } catch (ServiceException se) {
/* 105 */             if ("account.NO_SUCH_MEMBER".equals(se.getCode())) {
/* 106 */               ZimbraLog.misc.debug("Member not found in dlist; skipping", se);
/*     */             } else {
/* 108 */               throw se;
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/AccountStatus.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */